/*
 * @Author: Setsuna
 * @Email: 601890383@qq.com
 * @FilePath: \src\pages\QuotaManage\InventoryTransfer\components\EditInventoryTransfer.tsx
 * @Date: 2021-12-03 15:54:40
 * @LastEditTime: 2022-01-14 11:02:32
 */
import UdSelect from '@/components/UdFormControls/UdSelect'
import apis from '@/apis/AboutQuota'
import { http, UdForm, validators } from '@/lib'
import { Input, InputNumber, message, Spin } from 'antd'
import { WrappedFormUtils } from 'antd/lib/form/Form'
import TextArea from 'antd/lib/input/TextArea'
import React, { Component } from 'react'

interface Props {
  record: any
}
interface State {
  uploading: boolean
  downloading: boolean
}

export default class EditInventoryTransfer extends Component<Props, State> {
  private record = this.props.record || {}
  private labelCol: any = { span: 4 }
  private wrapperCol: any = { span: 20 }
  private form: WrappedFormUtils
  state: State = {
    uploading: false,
    downloading: false,
  }

  private onOk = e => {
    this.form.validateFields((err, values) => {
      if (!err) {
        let params = { ...this.record, ...values }
        e.drawerBtnLoading()
        http
          .post(apis.updateCheckTransfer, params)
          .then(res => {
            message.success('操作成功')
            e.close()
          })
          .catch(() => {
            e.drawerBtnLoadingHide()
          })
      } else {
        console.log(err)
      }
    })
  }

  render() {
    return (
      <Spin
        spinning={this.state.uploading || this.state.downloading}
        tip={this.state.uploading ? '上传中，请稍后...' : '下载中，请稍后...'}
      >
        <UdForm
          values={{ ...this.record }}
          getForm={form => (this.form = form)}
          labelCol={this.labelCol}
          wrapperCol={this.wrapperCol}
          items={[
            {
              label: '销售组织',
              id: 'brandName',
              render: () => <Input readOnly />,
            },
            {
              id: 'inventoryCycle',
              label: '盘点周期',
              render: () => <Input readOnly />,
            },
            {
              id: 'prodName',
              label: '物料描述',
              render: () => <Input readOnly />,
            },
            {
              id: 'dealerName',
              label: '客户名称',
              render: () => <Input readOnly />,
            },
            {
              id: 'number',
              label: '调入调出',
              rules: [validators.required],
              render: () => <InputNumber style={{ width: '100%' }} precision={0} />,
            },
            {
              id: 'remark',
              label: '备注信息',
              render: <TextArea rows={3} maxLength={200} />,
            },
          ]}
        />
      </Spin>
    )
  }
}
